package com.zhan.jpa.util.page;

import com.zhan.utils.page.PageResult;
import org.springframework.data.domain.Page;

public class PageUtils<T> {

    private static PageUtils pageUtils = new PageUtils<>();

    private PageUtils() {
    }

    public static PageUtils getInstance() {
        return pageUtils;
    }

    public PageResult<T> changeData(Page<T> data) {
        PageResult<T> result = new PageResult<>();
        result.setData(data.getContent());
        result.setCurrent(data.getNumber());
        result.setPageNum(data.getTotalPages());
        result.setSize(data.getSize());
        result.setTotal(data.getTotalElements());
        return result;
    }

}
